package com.hh.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hh.demo.entity.Book;
import com.hh.demo.entity.Bookinfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 吉吉国王
 * @since 2022-07-11
 */
@Mapper
public interface BookMapper extends BaseMapper<Book> {
    @Select("select * from book")
    List<Book> queryAll();
    @Select("select `bookCard` from bookinfo")
    List<Bookinfo> queryBookCard();
    @Update("update book set returnDate=#{returnDate},borrowStatus='已归还',bookNum=bookNum+1 where borrower=#{borrower}")
    void updateBook(String borrower,String returnDate);
    @Select("select borrower,count(*) as bookNum from book where borrowStatus='已借阅' group by borrower ")
    List<Book> queryCount();
    @Select("select * from book where bookNo=#{bookNo}")
    List<Book> queryBookBybookNo(String bookNo);
    @Select("select * from book where borrower=#{borrower}")
    List<Book> queryBookByBorrower(String borrower);
    @Select("select * from book where borrowTime=#{borrowTime}")
    List<Book> queryBookByborrowTime(String borrowTime);
    @Insert("insert into book(bookNo,bookName,author,borrower,borrowDate,returnDate,borrowStatus,bookNum) " +
            "values (#{bookNo},#{bookName},#{author},#{borrower},#{borrowDate},#{returnDate},#{borrowStatus},#{bookNum})")
    void insertBook(Book book);
}
